<template>
  <div>
    <page-list :x-uri="uri" :doactions="doactions" :custom-components="custom" :checkbox-item="false">
      <!-- 自定义tab -->
      <template v-slot:page-tabs>
        <tabs />
      </template>
    </page-list>
  </div>
</template>

<script>
import PageList from '@public/template/page_list.vue';
import Money from './components/money.vue';
import Tabs from './tabs';
import { moneySymbol } from '@/common/js/filters';

export default {
  components: {
    PageList,
    Tabs
  },
  inject: ['reload'],
  data() {
    return {
      uri: '/admin/finance/refund/wait',
      doactions: [
        {
          title: '通过',
          callback: this.handleDone
        },
        {
          title: '驳回',
          callback: this.handleReject
        }
      ],
      custom: {
        payment: Money
      }
    };
  },
  methods: {
    // 通过
    handleDone({ row }) {
      const infos = [
        { title: '订单号', value: row.order_no },
        { title: '退款申请用户手机号', value: row.user },
        { title: '退款申请时间', value: row.create_time },
        { title: '退款项目', value: row.order_title },
        { title: '退款金额', value: moneySymbol(row.payment) },
        { title: '退款到账方式', value: row.payment_type }
      ];
      this.$message
        .makeSureConfirm(this.$createElement, 3, infos, '确认退款申请')
        .then(() => {
          this.$http.post(
            '/admin/finance/refund/' + row.order_no + '/done',
            { order_no: row.order_no },
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(_ => {});
    },
    // 驳回
    handleReject({ row }) {
      this.$box
        .confirm('确认驳回退款申请？')
        .then(() => {
          this.$http.delete(
            '/admin/finance/refund/' + row.order_no + '/reject',
            { order_no: row.order_no },
            response => {
              this.$message.success(response.msg, _ => {
                this.reload();
              });
            },
            error => {
              this.$message.error(error.msg);
            }
          );
        })
        .catch(() => {});
    }
  }
};
</script>
